// var mysql = require('mysql');
var pgOpt = require('pg');

// var link = mysql.createConnection({
//     host : "localhost",
//     user : "root",
//     password : "111111",
//     database : "comments"
// });

const pgConfig = {
    user: 'root',           // 数据库用户名
    database: 'testdb',       // 数据库
    password: '123456',       // 数据库密码
    host: 'localhost',        // 数据库所在IP
    port: '5432'                // 连接端口
};
const pool = new pgOpt.Pool(pgConfig);

pool.connect(function(error, client, done) {
    if(error){
        console.log("Database connection failed："+ error.stack);
        return ;
    }
    console.log("The database connection is successful.");
})


// link.connect(function(err){
//     if(err){
//         console.log("Database connection failed："+ err.stack);
//         return ;
//     }
//     console.log("The database connection is successful.");
// });

// module.exports = link;
module.exports = {query: (text, params) => pool.query(text, params) };